import type { ElMessageBoxOptions, MessageOptions, NotificationOptions } from 'element-plus'

interface ConfirmParams {
  icon?: 'version' | 'warn' | 'info' | 'error' | 'success' | string
  title?: string
  contentTitle?: string
  message?: string
  option?: ElMessageBoxOptions
}

class MessageBox {
  /**
   * @param icon 图标类型
   * @param title 弹窗框标题
   * @param contentTitle 内容标题
   * @param message 描述内容（支持 HTML 标签）
   * @param option element-plus 的 messageBox 配置项wenj
   */
  confirm(params: ConfirmParams = {}) {
    const {
      icon = 'warn',
      title = '操作确认',
      contentTitle = '',
      message = '',
      option = {}
    } = params
    return ElMessageBox.confirm(
      `${contentTitle ? '<h3>' + contentTitle + '</h3>' : ''}${message}`,
      title,
      {
        icon: () =>
          h('img', { class: 'icon', src: icon.indexOf('assets') > -1 ? icon : getIconUrl(icon) }),
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        dangerouslyUseHTMLString: true,
        customClass: 'c-message-box',
        ...option
      }
    )
  }
}

function getIconUrl(name: string) {
  const path = new URL(`../assets/images/components/icon-message-box-${name}.png`, import.meta.url)
  return path.href
}

export default new MessageBox()
